<!DOCTYPE html>
<html>
        <head>
                <title>SpeedPHP CodeBuilder</title>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
        </head>
        <body>
                <script src="bootstrap/js/jquery.min.js"></script>
                <script src="bootstrap/js/bootstrap.js"></script>

                <!-- header -->
                <div class="navbar navbar-inverse" style="position: static;">
                        <div class="navbar-inner">
                                <div class="container">
                                        <a class="btn btn-navbar" data-toggle="collapse" data-target=".navbar-inverse-collapse">
                                                <span class="icon-bar"></span>
                                                <span class="icon-bar"></span>
                                                <span class="icon-bar"></span>
                                        </a>
                                        <a class="brand" href="#">CodeBuilder</a>
                                        <div class="nav-collapse collapse navbar-inverse-collapse">

                                                <ul class="nav pull-right">
                                                        <li><a href="<{spUrl c=CodeBuilder a=logout}>">Logout</a></li>
                                                </ul>
                                        </div><!-- /.nav-collapse -->
                                </div>
                        </div><!-- /navbar-inner -->
                </div>

                <!-- content -->
                <div class="container-fluid">
                        <div class="row-fluid">
                                <div class="span2">
                                        <ul class="nav nav-pills nav-stacked">
                                                <li><a href="#">Introduce</a></li>
                                                <li><a href="<{spUrl c=CodeBuilder a=genController}>">Controller</a></li>
                                                <li><a href="<{spUrl c=CodeBuilder a=genCURD}>">CURD</a></li>
                                                <li class="active"><a href="<{spUrl c=CodeBuilder a=genModel}>">Model</a></li>
                                        </ul>
                                        <!--Sidebar content-->
                                </div>
                                <div class="span10">
                                        <form action="<{spUrl c=CodeBuilder a=genModelAction}>" method="post" class="form-horizontal">
                                                <div class="control-group">
                                                        <label class="control-label" for="inputEmail">表前缀：</label>
                                                        <div class="controls">
                                                                <input name="modelTablePrefix" type="text" value="<{$tpl_prefix}>" readonly="true" />
                                                        </div>
                                                </div>

                                                <div class="control-group">
                                                        <label class="control-label" for="inputEmail">请选择数据表：</label>
                                                        <div class="controls">
                                                                <select name="modelTable">
									<option value="-1">请选择表</option>
                                                                        <{foreach $tpl_tables item=table}>
                                                                        <{assign var="tmp" value=$table|array_pop}>
                                                                        <option value="<{$tmp}>"><{$tmp}></option>
                                                                        <{/foreach}>
                                                                </select>
                                                        </div>
                                                </div>

                                                <div class="control-group">
                                                        <label class="control-label" for="inputEmail">请输入Model类名：</label>
                                                        <div class="controls">
                                                                <input name="modelName" type="text" />
                                                        </div>
                                                </div>

                                                <input type="hidden" name="genAction" value="preview" />

                                                <div class="control-group">
                                                        <div class="controls">
                                                                <input id="gen" type="button" class="btn btn-primary" value="生成" />
                                                                <input id="preview" type="button" class="btn" value="预览" />
                                                        </div>
                                                </div>
                                        </form>
                                        <!--Body content-->

                                        <!-- Preview -->
					<{if $tpl_preview == true}>
					<div class="row">
						<div class="span12">
							<{if $tpl_codeFile_overwrite == true}>
							<div class="alert"><strong>警告!</strong> 新生成的文件将覆盖已经存在的Model文件。</div>
							<{/if}>
							<p class="text-success">将在以下位置生成代码：<{$tpl_codePath}></p>
						</div>
					</div>
					<div class="row">
						<div class="span12">
							<pre>
<{$tpl_codePreview|htmlspecialchars}>
							</pre>
						</div>
					</div>
					<{/if}>
					
					<!-- Gen -->
					<{if $tpl_gen == true}>
					<div class="row">
						<div class="span12">
							<{if $tpl_success > 0}>
							<p class="text-success">成功在以下位置生成代码：<{$tpl_codePath}></p>
							<{else}>
							<p class="text-error">以下位置生成代码失败：<{$tpl_codePath}> 请检查是否存在model文件夹或model文件夹是否有写入权限。</p>
							<{/if}>
						</div>
					</div>
					<{/if}>
                                </div>
                        </div>
                </div>
                <script>
                        (function($){
                                $('[name="modelTable"]').change(function(){
                                        var modelName = '';
                                        if($('[name="modelTablePrefix"]').val() != ''){
                                                modelName = $(this).val().replace($('[name="modelTablePrefix"]').val(),'');
                                        }
                                        else{
                                                modelName = $(this).val();
                                        }
                                        modelName = tableNameTranser(modelName);
                                        $('[name="modelName"]').val(modelName);
                                });
                                
                                $('#preview').click(function(){
                                        $('[name="genAction"]').val('preview');
                                        $('form').submit();
                                });
                                
                                $('#gen').click(function(){
                                        $('[name="genAction"]').val('gen');
                                        $('form').submit();
                                });
                                
                                function tableNameTranser(tableName){
                                        if(tableName.indexOf('_') > 0){
                                                var tmpTableName = tableName.split('_');
                                                for(i=0;i<tmpTableName.length;i++){
                                                        tmpTableName[i] = tmpTableName[i].replace(/(^|\s+)\w/g,function(s){return s.toUpperCase();});
                                                }
                                                tableName = tmpTableName.join('');
                                        }
                                        else{
                                                tableName = tableName.replace(/(^|\s+)\w/g,function(s){return s.toUpperCase();});
                                        }
                                        return tableName;
                                }
                        })(jQuery);
                </script>
		
		<{if $tpl_preview == true || $tpl_gen == true}>
		<script>
			(function($){
				$('[name="modelTablePrefix"]').val('<{$tpl_modelTablePrefix}>');
				$('[name="modelName"]').val('<{$tpl_modelName}>');
				$('[name="modelTable"]').val('<{$tpl_modelTable}>');
			})(jQuery)
		</script>
		<{/if}>
        </body>
</html>
